<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-03 16:49:32
 * @LastEditTime: 2019-11-23 16:22:33
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../css/vant_new.css">
	<link rel="stylesheet" type="text/css" href="../css/base.css" />
	<script type="text/javascript" src="../script/jquery.js"></script>
	<script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
	<script type="text/javascript" src="../script/vue.min.js"></script>
	<script type="text/javascript" src="../script/vant_new.min.js"></script>
	<script type="text/javascript" src="../script/fastclick.js"></script>
	<script type="text/javascript" src="../script/base.js"></script>
	<style type="text/css">
		.p .van-cell__title {
			max-width: none;
		}

		.p .van-cell__value {
			text-align: right;
		}

		.p .label {
			line-height: 22px;
			text-align: center;
			font-weight: 500;
			font-size: 13px;
		}

		.p .label .label-value {
			color: #3a3a3a;
			font-size: 14px;
		}

		.p .border {
			border-right: 1px solid #ebedf0;
		}


		.van-popup {
			width: 100%;
			/* height: 100%; */
		}

		.van-popup .filter-list {
			height: calc(100% - 44px);
			padding: 30px 0 20px 10px;
			overflow-y: auto;
			-webkit-overflow-scrolling: touch;
		}

		.van-popup .filter-txt {
			line-height: 42px;
		}

		.van-popup .van-row {
			border-bottom: 1px solid #ebedf0;
			padding-bottom: 5px;
		}

		.van-popup .filter-condition {
			height: 26px;
			line-height: 26px;
			width: 80%;
			margin-bottom: 12px;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}

		.van-popup .price-section {
			width: 100%;
			border: 0;
			height: 28px;
			border-radius: 14px;
			background: #efefef;
			text-align: center;
			font-size: 12px;
			color: #aeabb1;
		}

		.van-popup .price-line {
			text-align: center;
			height: 28px;
			line-height: 28px;
			color: #e5e5e5;
			font-size: 12px;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="init-full">
			<van-nav-bar class="head" title="库存查询" left-arrow @click-left="onClickLeft">
				<div slot="right" class="head-right">
					<span @click="showSearch = true;">
						<img src="../image/search.png" />
					</span>
				</div>
			</van-nav-bar>
			<div class="body-no-bottom">
				<div class="content">

					<van-list v-model="listLoading" :finished="listFinished" finished-text="没有更多了" @load="listOnLoad">
						<div class="p">

							<van-cell v-for="row in filterResult" :title="row.ProductName" @click="intoReport(row)">
								<div slot="label" class="label">
									<van-swipe-cell :disabled="disabledJJ">
										<div>
											<van-row gutter="8">
												<!-- <van-col span="6" class="border">
														<div>进价</div>
														<div class="label-value">{{row.CPrice}}</div>
													</van-col> -->
												<van-col span="8" class="border">
													<div>售价</div>
													<div class="label-value">{{row.DPrice}}</div>
												</van-col>
												<van-col span="8" class="border">
													<div>账面库存</div>
													<div class="label-value">{{row.XNum}}</div>
												</van-col>
												<van-col span="8">
													<div>虚拟库存</div>
													<div class="label-value">{{row.BNum}}</div>
												</van-col>
											</van-row>
										</div>
										<div slot="right">
											<div style="width: 100px;">
												<div>进价</div>
												<div class="label-value" style="color: #cd1b21;">{{row.CPrice}}</div>
											</div>
										</div>
									</van-swipe-cell>

								</div>
							</van-cell>


						</div>
					</van-list>



				</div>
				<van-loading v-if="showLoading" />
			</div>

			<van-popup v-model="showSearch" round position="bottom">
				<div>
					<van-cell title="仓库" :value="filter.S_StockName" is-link @click="openScreen(-1,30)">
					</van-cell>
					<van-cell title="库位" :value="filter.S_CargoName" is-link @click="openScreen(-1,31)">
					</van-cell>
					<van-cell title="商品分类" :value="filter.S_PrTreeName" is-link @click="openScreen(-1,69)">
					</van-cell>
					<van-field label="产品名称" v-model="filter.S_Product"></van-field>
				</div>
				<div class="btn-padding">
					<van-button type="primary" block style="border-radius: 0;" @click="search">查询</van-button>
				</div>
			</van-popup>


		</div>
	</div>
</body>

<script type="text/javascript">
	var vm;



	apiready = function () {
		//$('.init-full').show();

		api.addEventListener({
			name: 'selectRow'
		}, function (ret, err) {
			var selectType = ret.value.selectType;
			var type = ret.value.type;
			var row = ret.value.row;
			if (selectType == 30) {
				if (vm.filter.S_StockID != row.id) {
					vm.filter.S_CargoName = '';
					vm.filter.S_CargoID = 0;
				}
				vm.filter.S_StockName = row.name;
				vm.filter.S_StockID = row.id;
			}
			if (selectType == 31) {
				if (row) {
					vm.filter.S_CargoName = row.name;
					vm.filter.S_CargoID = row.id;
				} else {
					vm.filter.S_CargoName = '';
					vm.filter.S_CargoID = 0;
				}

			}
			if (selectType == 69) {
				if (row) {
					vm.filter.S_PrTreeName = row.name;
					vm.filter.S_PrTreeID = row.code;
				} else {
					vm.filter.S_PrTreeName = '';
					vm.filter.S_PrTreeID = 0;
				}

			}

		});

		var userInfo = FLD.getUserInfo();
		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				listLoading: false,
				listFinished: true,
				filterResult: [],
				filter: {
					S_StockID: userInfo.S_StockID,
					S_StockName: userInfo.S_StockName,
					S_CargoID: 0,
					S_CargoName: '',
					S_PrTreeID: 0,
					S_PrTreeName: '',
					S_Product: api.pageParam.searchKey || '',
					S_PageSize: 20,
					S_Pageindex: 1
				},
				showSearch: false,
				disabledJJ:false
			},
			created: function () {
				this.getFilertData();
				this.getPageRole();
			},
			methods: {
				getPageRole() {
					var that = this;
					FLD.ajax('APP_JHJGBKJM', {}, function (res) {
						if(res.ds.length){
							if(res.ds[0].status && res.ds[0].status == 500){
								that.disabledJJ = true;
							}
						}
					})
				},
				getFilertData() {
					var that = this;
					that.showLoading = true;
					FLD.ajax('AP_StockNumG', that.filter, function (res) {

						that.showLoading = false;
						that.listFinished = false;
						that.filterResult = res.ds;
					})
				},
				listOnLoad() {
					var that = this;
					that.filter.S_Pageindex++;
					FLD.ajax('AP_StockNumG', that.filter, function (res) {
						that.listLoading = false;
						if (res.ds.length == 0) {
							that.listFinished = true;
						}
						that.filterResult = that.filterResult.concat(res.ds);
					})
				},
				openScreen(type, index) {
					var that = this;
					var obj = null;

					if (index == 31) {
						obj = {
							S_Type: 31,
							S_Cont: '',
							S_BranchID: userInfo.S_BranchID,
							S_SXZ: that.filter.S_StockID,
							S_StockID: that.filter.S_StockID,
							S_CargoID: that.filter.S_CargoID,
							S_BarCode: '',
							S_PriceN: 0,
							S_ProductID: 0
						}
					} else {
						obj = {
							S_Type: index,
							S_Cont: '',
							S_BranchID: userInfo.S_BranchID,
							S_SXZ: '',
							S_StockID: that.filter.S_StockID,
							S_CargoID: that.filter.S_CargoID,
							S_BarCode: '',
							S_PriceN: 0,
							S_ProductID: 0
						}
					}

					api.openWin({
						name: '筛选' + index,
						url: 'common/baseScreen.html',
						reload: true,
						slidBackEnabled: false,
						pageParam: {
							filterData: obj,
							type: type,
							allowClear: (index == 30 ? false : true)
						}
					})

				},
				intoReport(row) {
					var that = this;
					api.openWin({
						name: '虚拟库存明细查询_0',
						url: 'common/formConfigReport.html',
						reload: true,
						slidBackEnabled: false,
						pageParam: {
							objName: '虚拟库存明细查询',
							formData: {
								StockID: row.StockID,
								CargoID: row.CargoID,
								ProductID: row.ProductID
							}
						}
					})
				},
				search() {
					this.showSearch = false;
					this.filter.S_Pageindex = 1;
					this.getFilertData();
				},
				onClickLeft() {
					api.closeWin();
				}
			}
		})
	};
</script>

</html>